package com.sitanyun.merchant.guide.frament.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sitanyun.merchant.guide.R;
import com.sitanyun.merchant.guide.base.BaseActivity;
import com.sitanyun.merchant.guide.view.activity.MainActivity;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 首次进入设置密码成功界面
 */
public class SuccessPasswordActivity extends BaseActivity {

    @BindView(R.id.showdown)
    TextView showdown;
    @BindView(R.id.tv_gohome)
    TextView tvGohome;
    @BindView(R.id.ll_foget_for)
    LinearLayout llFogetFor;
    private int recLen = 6;//跳过倒计时提示6秒
    Timer timer = new Timer();
    @Override
    public int getLayoutId() {
        return R.layout.activity_success_password;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        setFindViewById(true);
        setTitleStr("设置密码");
    }

    @Override
    public void initView() {
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        recLen--;
                        showdown.setText(recLen + "秒后进入登录界面");
                        if (recLen == 0) {
                            timer.cancel();
                            showdown.setVisibility(View.GONE);//倒计时到0隐藏字体
                            Intent intent = new Intent(SuccessPasswordActivity.this, MainActivity.class)
                                    .putExtra("cid","null");
                            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            finish();
                        }
                    }
                });

            }
        };

        timer.schedule(timerTask, 1000, 1000);//等待时间一秒，停顿时间一秒

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.tv_gohome)
    public void onViewClicked() {

        Intent intent = new Intent(SuccessPasswordActivity.this, MainActivity.class)
                .putExtra("cid","null");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
    }

    @Override
    protected void onPause() {
        super.onPause();
        timer.cancel();
    }
}
